<%@page import="cn.lei.PageBean"%>
<%@page import="cn.lei.Student"%>
<%@page import="java.util.List"%>
<%@page import="cn.severimpl.StudentServiceImpl"%>
<%@page import="cn.isever.IStudentService"%>
<%@page import="org.eclipse.jdt.internal.compiler.batch.Main"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

		<link rel="stylesheet" type="text/css" href="lib/bootstrap/css/bootstrap.css" />
		<!--引入jquery-->
		<script type="text/javascript" src="lib/jquery-1.11.1.js" ></script>
		<!--引入js-->
		<script type="text/javascript" src="lib/bootstrap/js/bootstrap.js" ></script>
		<script type="text/javascript" src="../../jquery-1.11.1.js"></script>
		<script type="text/javascript">
		
		
		<!--这是删除方法弹框 -->
		function deleteById(id){
			//用户点了确定，confirm返回的就是true
			//用户点了取消，confirm返回的就是false
			var isDel = confirm("您确认要删除吗?");	//相当于弹框
			if(isDel){
				location.href = <%=request.getContextPath() %>+"/student?method=deleteById&id="+id;
			}
		}
		
		function selectAll(){
			//得到上面全选、反选按钮的状态
			var isChecked = $("#selectAlls").prop("checked");
			//下面所有checkbox状态和上面全选/反选checkbox的状态一致
			$("inpute[name=selectIds]").prop("checked",isChecked);
			}
		
		function deleteAll(){
			$("#mainForm").attr("action",<%=request.getContextPath()%>+"/student?method=deleteAll");
			//用代码方式提交表单
			$("#mainForm").submit();

		}
		
		function fanxuan(){
			  //反选
            //遍历全部复选框，选中就取消，未选中就设置选中
            var fan = document.getElementsByClassName("checkall");
				for (var i = 0; i < fan.length; i++) {
					//checkboxs[i].checked == true ? checkboxs[i].checked = false : checkboxs[i].checked = true; 
					var checkedStatus = fan[i].checked;
					if(checkedStatus){
						fan[i].checked=false;
						
					}else{
						fan[i].checked=true;
					}
				}
			}
           		
           		
           
		
		
		
		</script>
</head>
<body>
<style type="text/css">
		.align-center{
	    width: 800px;
		margin : 10px auto;
		}
		table{
		table-layout : fixed;
		word-break : break-all;
		}
</style>
 <!-- JSP脚本 -->
 
 <!-- JSP表达式 -->
 <%
 		PageBean pageBean = (PageBean)request.getAttribute("pageBean");	//其中request是内置方法，跟setAttribute配套就是获得这个值
     %>

	<a href="student_add.jsp">添加</a>
	<a href="javascript:deleteAll()">批量删除</a> <!-- 这句话是点击执行js里面的方法 -->
	<form action="<%=request.getContextPath() %>/student?method=pageList"  method="post">
		姓名:<input type="text" name="name"/>
		<input type="submit" value="搜索"/>
    
	</form>
<!-- 遍历List<Student>集合 -->
	<button onclick="fanxuan()">反选</button>
	<div class = ".align-center">
		<table class="table table-striped table-bordered table-hover table-condensed">
		<tr>
<!-- 			<td>全选/双击多选<input type="checkbox" onclick="checkall()" ondblclick="unclick()" />反选<input type="checkbox" /></td> -->
			<td>全选/全不选<input type="checkbox" id="selectAlls" onclick="selectAll()" /></td>
			
			<td>ID</td>
			<td>姓名</td>
			<td>年龄</td>
			<td>性别</td>
			<td>修改</td>
			<td>删除</td>
		</tr>
		<c:forEach items="${pageBean.list}" var="student">
		<tr>
			<td><input type="checkbox" name = "selectIds" value="${stduent.id}"/></td>
			<td>${stduent.id}</td>
			<td>${stduent.name}</td>
			<td>${stduent.age}</td>
			<td>${stduent.gender}</td>
			<td><a href="<%=request.getContextPath() %>/student?method=toUpdate&id=${stduent.id}">修改</a></td>
			<td><a href="javascript:deleteById(${stduent.id})">删除</a></td>
		</tr>
		
		
		</c:forEach>
		
	<%-- 	
		  <%
			for(Student student:pageBean.getList()){
		%> 
		<tr>
			<td><input type="checkbox" name = "selectIds" value=<%=student.getId() %>/></td>
			<td><%=student.getId()%></td>
			<td><%=student.getName()%></td>
			<td><%=student.getAge()%></td>
			<td><%=student.getGender()%></td>
			<td><a href="<%=request.getContextPath() %>/student?method=toUpdate&id=<%=student.getId()%>">修改</a></td>
			<td><a href="javascript:deleteById(<%=student.getId()%>)">删除</a></td>
		</tr>
		<% 
		}
		%> --%>
		</table> 
		</div>
		<nav aria-label="Page navigation">
		 <ul class="pagination">
		 <li>
		 <%if(pageBean.getPageNo()>1){
			 
			 %>
			  <a href="<%=request.getContextPath()%>/student?method=pageList&pageNo=<%=pageBean.getPageNo()-1%>&pageSize=3" aria-label="Previous">
		<% } else{
		}%>
		 
		    
		     
		        <span aria-hidden="true">&laquo;</span>
		      </a>
		    </li>
		    <%
		    	for(int i = 1;i<= pageBean.getTotalPage();i++){
		    		if(i==pageBean.getPageNo()){
		    			%>
		    		
		    		 	 <li class="active"><a href="#"><%=i %></a></li>
		    		<%}else{%>
		    		
		    		 <li><a href="<%=request.getContextPath()%>/student?method=pageList&pageNo=<%=i%>&pageSize=3"><%=i %></a></li>
		    	<%	}
		    
		   
		  
		    	 }%>
		    <li>
		    <%
		    if(pageBean.getPageNo()<pageBean.getTotalPage()){
		    	
		   
		    %>
		      <a href="<%=request.getContextPath()%>/student?method=pageList&pageNo=<%=pageBean.getPageNo()+1%>&pageSize=3" aria-label="Next">
		      <% }else{} %>
		        <span aria-hidden="true">&raquo;</span>
		      </a>
		    </li>
		  </ul>
		</nav>
</body>
</html>